home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / pc / pr42sdk / examples / projects / edl / ex-raw.c next >
Encoding:
C/C++ Source or Header  |  1995-10-07  |  14.7 KB  |  593 lines

  1. //========================================================================================
  2. //
  3. // Ex-raw.c - Generic EDL export module.
  4. //
  5. // Part of the Adobe Premiere 4.2 Plug-in Developer's Toolkit.
  6. //
  7. // Copyright ⌐ 1993-96, Adobe Systems Incorporated, all rights reserved worldwide.
  8. //
  9. // Written by Randy Ubillos, Bryan K. "Beaker" Ressler, Nick Schlott.
  10. //
  11. // Version    1.00    10/20/93    Original version.
  12. // Version    1.01    10/30/94    Windows version.
  13. // Version    1.02    1/10/96        Updated for Premiere 4.2 and MSVC++ 2.2 & 4.2.
  14. //
  15. //========================================================================================
  16.  
  17. #include <windows.h>
  18.  
  19. #include "Compat.h"
  20. #include "Premiere.h"
  21.  
  22.  
  23. HINSTANCE    ghInst;
  24.  
  25. int ParseBlock(BlockRec *theblock, HFILE ref, int indent);
  26.  
  27.  
  28. BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
  29. {
  30.     switch (dwReason)
  31.     {
  32.         case DLL_PROCESS_ATTACH:
  33.             ghInst = hDLL;
  34.             break;
  35.  
  36.         case DLL_THREAD_ATTACH:
  37.             break;
  38.  
  39.         case DLL_THREAD_DETACH:
  40.             break;
  41.  
  42.         case DLL_PROCESS_DETACH:
  43.             break;
  44.     }
  45.     return(TRUE);
  46. }
  47.  
  48.  
  49. //-----------------------------------------------
  50. // Chop the extension off a file name
  51.  
  52. void ChopExtension (LPSTR str)
  53. {
  54.     short n;
  55.  
  56.     n = lstrlen(str)-1;
  57.     while(n)
  58.     {
  59.         if(str[n] == '.')
  60.         {
  61.             str[n] = 0;
  62.             break;
  63.         }
  64.         else if(str[n] == '\\')
  65.             break;
  66.         n--;
  67.     }
  68. }
  69.  
  70.  
  71. //-----------------------------------------------
  72. // Strip the file name off a full path
  73.  
  74. LPSTR FileNameFromPath (LPSTR s)
  75. {
  76.     int    idx;
  77.  
  78.     if(s[1] != ':')
  79.         return s;
  80.  
  81.     idx = lstrlen(s);
  82.  
  83.     while(idx && s[idx] != '\\')
  84.         idx--;
  85.     return &s[idx+1+(idx==0)];
  86. }
  87.  
  88.  
  89. //-------------------------------------------------------------------------------------------
  90. int PutFile (char *name, char *caption)
  91. {
  92.     OPENFILENAME ofn;
  93.  
  94.     ofn.lStructSize = sizeof(OPENFILENAME);
  95.     ofn.lpstrFilter = "*.edl";
  96.     ofn.hwndOwner = GetLastActivePopup(GetMainWnd());
  97.     ofn.hInstance = ghInst;
  98.     ofn.nFilterIndex = 0;
  99.     ofn.lpstrFileTitle = NULL;
  100.     ofn.nMaxFileTitle = 31;
  101.     name[0] = 0;
  102.     ofn.lpstrFile = (LPSTR)name;
  103.     ofn.nMaxFile = _MAX_PATH;
  104.     ofn.lpstrInitialDir = NULL;
  105.     ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
  106.     ofn.lpstrCustomFilter = NULL;
  107.     ofn.nMaxCustFilter = 0;
  108.     ofn.nFileOffset = ofn.nFileExtension = 0;
  109.     ofn.lpstrDefExt = "EDL";
  110.     ofn.lCustData = 0;
  111.     ofn.lpfnHook = NULL;
  112.     ofn.lpTemplateName = NULL;
  113.     ofn.lpstrTitle=NULL;
  114.  
  115.     if (caption) ofn.lpstrTitle = caption;
  116.     return GetSaveFileName(&ofn);
  117. }
  118.  
  119.  
  120. //-------------------------------------------------------------------------------------------
  121. // Export
  122.  
  123. int PRMEXPORT xExport (short selector, ExportHandle theData)
  124. {
  125.     short        result = 0;
  126.     HFILE        ref;
  127.     Str63        str1;
  128.     FSSpec        thespec;
  129.     OFSTRUCT    of;
  130.  
  131.     switch (selector)
  132.     {
  133.         case exExecute:
  134.             LoadString(ghInst, 10001, str1, 63);
  135.  
  136.             lstrcpy(thespec.name, FileNameFromPath((*theData)->projectName));
  137.             ChopExtension(thespec.name);
  138.             LoadString(ghInst,10002, &thespec.name[lstrlen(thespec.name)], 10);
  139.             
  140.             if (PutFile(thespec.name, str1))
  141.             {
  142.                 OpenFile(thespec.name, &of, OF_DELETE);
  143.                 ref = OpenFile(thespec.name, &of, OF_CREATE | OF_READWRITE);
  144.                 if (ref != HFILE_ERROR)
  145.                 {
  146.                     HLock((*theData)->dataHandle);
  147.                     ParseBlock((BlockRec*)*(*theData)->dataHandle,ref,0);
  148.                     HUnlock((*theData)->dataHandle);
  149.                     _lclose(ref);
  150.                 }
  151.             }
  152.             break;
  153.         case exTrue30fps:
  154.             result = true;
  155.             break;
  156.     }
  157.     return(result);
  158. }
  159.  
  160. //-------------------------------------------------------------------------------------------
  161. // Write data to a file
  162.  
  163. int WriteFileX (HFILE ref, Ptr data, long length)
  164. {
  165.     return(_hwrite(ref,data,length) != length);
  166. }
  167.  
  168. //-------------------------------------------------------------------------------------------
  169. // Send a character to a file
  170.  
  171. int SendChar (HFILE ref, char ch)
  172. {
  173.     return(WriteFileX(ref,&ch,1));
  174. }
  175.  
  176. //-------------------------------------------------------------------------------------------
  177. // Send a string to a file
  178.  
  179. int WriteString (HFILE ref, char *str)
  180. {
  181.     return(WriteFileX(ref,str,lstrlen(str)));
  182. }
  183.  
  184. //-------------------------------------------------------------------------------------------
  185. // Send a number to a file
  186.  
  187. int SendNum (HFILE ref, long num)
  188. {
  189.     Str27 str;
  190.     
  191.     wsprintf(str, "%ld", num);
  192.     return(WriteString(ref,(char *)str));
  193. }
  194.  
  195. //-------------------------------------------------------------------------------------------
  196. // Send a string to a file
  197. // str is formatted like fprint (kind of...)
  198.  
  199. int SendStr (HFILE ref, char *str, long value, ...)
  200. {
  201.     char    *where,*last, *start, oldchar, temp[10];
  202.     short    param = 0, err = 0, i, num;
  203.     long    *parm = &value;
  204.     
  205.     where = str;
  206.     last = str + lstrlen(str);
  207.     while (!err && (where <= last))
  208.     {
  209.         start = where;
  210.         if (where[0] == '%')
  211.         {
  212.             switch (where[1])
  213.             {
  214.                 case 'd':
  215.                     err = SendNum(ref,parm[param++]);
  216.                     break;
  217.                 case 's':
  218.                     err = WriteString(ref,(char*)parm[param++]);
  219.                     break;
  220.                 case 't':
  221.                     temp[4] = 0;
  222.                     *((long*)(temp)) = parm[param++];
  223.                     err = WriteString(ref,temp);
  224.                     break;
  225.                 case 'b':
  226.                     temp[8] = 0;
  227.                     num = (short)parm[param++];
  228.                     for (i=0; i<=7; i++) temp[i] = num & (0x0080>>i) ? '1':'0';
  229.                     err = WriteString(ref,temp);
  230.                     break;
  231.             }
  232.             where += 2;
  233.         }
  234.         else
  235.         {
  236.             while ((where<=last) && (where[0]!='%'))
  237.                 where++;
  238.  
  239.             oldchar = *where;
  240.             *where = 0;
  241.             err = WriteString(ref,(char*)(start));
  242.             *where = oldchar;
  243.         }
  244.     }
  245.     return(err);
  246. }
  247.  
  248. //-------------------------------------------------------------------------------------------
  249. // send out spaces to do an indent
  250.  
  251. int SendIndent (HFILE ref, int amount)
  252. {
  253.     int i, err=0;
  254.     
  255.     for (i = 0; !err && (i<amount); i++) err = SendChar(ref, 9);
  256.     return(err);
  257. }
  258.  
  259. //-------------------------------------------------------------------------------------------
  260. // take apart a block
  261.  
  262. int ParseBlock (BlockRec *theblock, HFILE ref, int indent)
  263. {
  264.     int            i, count, svalue, err=0, mapping;
  265.     long        len, lvalue;
  266.     Rec_BLOK    rBLOK;
  267.     Rec_TREC    rTREC;
  268.     Rec_CLIP    rCLIP;
  269.     Rec_RPNT    rRPNT;
  270.     Rec_MREC    rMREC;
  271.     Rec_VIDI    rVIDI;
  272.     Rec_FXOP    rFXOP;
  273.     Rec_TIMB    rTIMB;
  274.     FSSpec        rFILE;
  275.     COLORREF    thecolor;
  276.     RECT        box;
  277.     POINT        pt;
  278.     char        str[32];
  279.     Ptr            pblock,p;
  280.     
  281.     err = SendIndent(ref, indent);
  282.     if (!err) err = SendChar(ref,'[');
  283.     if (!err) switch (theblock->type) {
  284.         case bBLOK:
  285.             len = sizeof(Rec_BLOK);
  286.             ExtractBlockData(theblock,&rBLOK,&len);
  287.             err = SendStr(ref,"'Adobe Premiere¬ 4.2 Generic Edit Decision List',Work_Start=%d,Work_End=%d",
  288.                                                                                         rBLOK.start,rBLOK.end);
  289.             break;
  290.         case bTRKB:
  291.             err = SendStr(ref,"Tracks",nil);
  292.             break;
  293.         case bTRAK:
  294.             err = SendStr(ref,"Track #%d",theblock->theID);
  295.             break;
  296.         case bFVID:
  297.             err = SendStr(ref,"Video",nil);
  298.             break;
  299.         case bFSUP:
  300.             err = SendStr(ref,"SuperImpose",nil);
  301.             break;
  302.         case bFAUD:
  303.             err = SendStr(ref,"Audio",nil);
  304.             break;
  305.         case bFF_X:
  306.             err = SendStr(ref,"FX",nil);
  307.             break;
  308.         case bAMAP:
  309.             len = sizeof(mapping);
  310.             ExtractBlockData(theblock, &mapping, &len);
  311.             err = SendStr(ref, "Mapping=%b",mapping);
  312.             break;
  313.         case bTREC:
  314.             len = sizeof(Rec_TREC);
  315.             ExtractBlockData(theblock,&rTREC,&len);
  316.             err = SendStr(ref,
  317.                               "Track_Record #%d, ClipID=%d, Start=%d, End=%d",
  318.                               theblock->theID,
  319.                               (long)rTREC.clipID,
  320.                               rTREC.start,
  321.                               rTREC.end);
  322.             break;
  323.         case bFXOP:
  324.             len = sizeof(Rec_FXOP);
  325.             ExtractBlockData(theblock,&rFXOP,&len);
  326.             err = SendStr(ref,
  327.                               "FX_Options,Corners=%b,Direction=%d,Start=%d,End=%d",
  328.                               (long)rFXOP.corners,
  329.                               (long)rFXOP.direction,
  330.                               (long)rFXOP.startPercent,
  331.                               (long)rFXOP.endPercent);
  332.             break;
  333.         case bFXDF:
  334.             len = sizeof(long);
  335.             ExtractBlockData(theblock,&lvalue,&len);
  336.             err = SendStr(ref,"FX_Type=%t",lvalue);
  337.             break;
  338.         case bEDGE:
  339.             len = sizeof(short);
  340.             ExtractBlockData(theblock,&svalue,&len);
  341.             err = SendStr(ref,"Edge,Thickness=%d",(long)svalue);
  342.             break;
  343.         case bRBND:
  344.             len = sizeof(short);
  345.             ExtractBlockData(theblock,&svalue,&len);
  346.             err = SendStr(ref,"RubberBand, Max=%d",(long)svalue);
  347.             break;
  348.         case bRPNT:
  349.             len = sizeof(Rec_RPNT);
  350.             ExtractBlockData(theblock,&rRPNT,&len);
  351.             err = SendStr(ref,
  352.                               "Band_Point #%d,h=%d,v=%d",
  353.                               theblock->theID,
  354.                               rRPNT.h,
  355.                               (long)rRPNT.v);
  356.             break;
  357.         case bOVER:
  358.             len = sizeof(short);
  359.             ExtractBlockData(theblock,&svalue,&len);
  360.             LoadString(ghInst, 10101+svalue, str,32);
  361.             err = SendStr(ref,"Overlay, Type='%s'",(long)str);
  362.             break;
  363.         case bCOLR:
  364.             len = sizeof(COLORREF);
  365.             ExtractBlockData(theblock,&thecolor,&len);
  366.             err = SendStr(ref,
  367.                               "Color,Red=%d,Green=%d,Blue=%d",
  368.                               (long)GetRValue(thecolor),
  369.                               (long)GetGValue(thecolor),
  370.                               (long)GetBValue(thecolor));
  371.             break;
  372.         case bSIMI:
  373.             len = sizeof(short);
  374.             ExtractBlockData(theblock,&svalue,&len);
  375.             err = SendStr(ref,"Similarity=%d",(long)svalue);
  376.             break;
  377.         case bBLND:
  378.             len = sizeof(short);
  379.             ExtractBlockData(theblock,&svalue,&len);
  380.             err = SendStr(ref,"Blend=%d",(long)svalue);
  381.             break;
  382.         case bTHRS:
  383.             len = sizeof(short);
  384.             ExtractBlockData(theblock,&svalue,&len);
  385.             err = SendStr(ref,"Threshold=%d",(long)svalue);
  386.             break;
  387.         case bCUTO:
  388.             len = sizeof(short);
  389.             ExtractBlockData(theblock,&svalue,&len);
  390.             err = SendStr(ref,"Cutoff=%d",(long)svalue);
  391.             break;
  392.         case bALIA:
  393.             len = sizeof(short);
  394.             ExtractBlockData(theblock,&svalue,&len);
  395.             err = SendStr(ref,"Anti-Aliasing=%d",(long)svalue);
  396.             break;
  397.         case bSHAD:
  398.             err = SendStr(ref,"Shadow",nil);
  399.             break;
  400.         case bRVRS:
  401.             err = SendStr(ref,"Key_Reversed",nil);
  402.             break;
  403.         case bGARB:
  404.             len = sizeof(RECT);
  405.             ExtractBlockData(theblock,&box,&len);
  406.             err = SendStr(ref,
  407.                               "Garbage_Matte,Left=%d,Top=%d,Right=%d,Bottom=%d",
  408.                               (long)box.left,
  409.                               (long)box.top,
  410.                               (long)box.right,
  411.                               (long)box.bottom);
  412.             break;        
  413.         case bPONT:
  414.             len = sizeof(POINT);
  415.             ExtractBlockData(theblock,&pt,&len);
  416.             err = SendStr(ref,
  417.                               "Point #%d,h=%d,v=%d",
  418.                               theblock->theID,
  419.                               (long)pt.x,
  420.                               (long)pt.y);
  421.             break;
  422.         case bMATI:
  423.             len = sizeof(short);
  424.             ExtractBlockData(theblock,&svalue,&len);
  425.             err = SendStr(ref,"MatteID=%d",(long)svalue);
  426.             break;
  427.         case bVFLT:
  428.             err = SendStr(ref,"Video_Filters",nil);
  429.             break;
  430.         case bAFLT:
  431.             err = SendStr(ref,"Audio_Filters",nil);
  432.             break;
  433.         case bFILT:
  434.             len = sizeof(short);
  435.             ExtractBlockData(theblock,&svalue,&len);
  436.             err = SendStr(ref,"FileID=%d",(long)svalue);
  437.             break;
  438.         case bMOTN:
  439.             len = sizeof(RECT);
  440.             ExtractBlockData(theblock,&box,&len);
  441.             err = SendStr(ref,
  442.                               "Motion,Left=%d,Top=%d,Right=%d,Bottom=%d",
  443.                               (long)box.left,
  444.                               (long)box.top,
  445.                               (long)box.right,
  446.                               (long)box.bottom);
  447.             break;
  448.         case bSMTH:
  449.             err = SendStr(ref,"Smooth",nil);
  450.             break;
  451.         case bMREC:
  452.             len = sizeof(Rec_MREC);
  453.             ExtractBlockData(theblock,&rMREC,&len);
  454.             err = SendStr(ref,
  455.                               "Motion_Point #%d,Zoom=%d,Time=%d,Delay=%d,Rotation=%d,h=%d,v=%d",
  456.                               theblock->theID,
  457.                               (long)rMREC.zoom,
  458.                               (long)rMREC.time,
  459.                               (long)rMREC.delay,
  460.                               (long)rMREC.rotation,
  461.                               (long)rMREC.spot.x,
  462.                               (long)rMREC.spot.y);
  463.             break;
  464.         case bDATA:
  465.             err = SendStr(ref,"Data #%d, %d bytes",theblock->theID,theblock->dataSize);
  466.             break;
  467.             
  468.         case bCLPB:
  469.             err = SendStr(ref,"Clips",nil);
  470.             break;
  471.         case bCLIP:
  472.             len = sizeof(Rec_CLIP);
  473.             ExtractBlockData(theblock,&rCLIP,&len);
  474.             err = SendStr(ref,
  475.                               "ClipID #%d,FileID=%d,In=%d,Out=%d",
  476.                               theblock->theID,
  477.                               (long)rCLIP.fileID,
  478.                               rCLIP.in,
  479.                               rCLIP.out);
  480.             break;
  481.         case bMARK:
  482.             len = sizeof(long);
  483.             ExtractBlockData(theblock,&lvalue,&len);
  484.             err = SendStr(ref,"Mark #%d, Location=%d",theblock->theID,lvalue);
  485.             break;
  486.         case bLOCK:
  487.             err = SendStr(ref,"Aspect_Locked",nil);
  488.             break;
  489.         case bRATE:
  490.             len = sizeof(short);
  491.             ExtractBlockData(theblock,&svalue,&len);
  492.             err = SendStr(ref,"Rate=%d",(long)svalue);
  493.             break;
  494.             
  495.         case bFILB:
  496.             err = SendStr(ref,"Files",nil);
  497.             break;
  498.         case bFILE:
  499.             err = SendStr(ref,"FileID #%d",theblock->theID);
  500.             break;
  501.         case bMACS:
  502.             len = sizeof(FSSpec);
  503.             ExtractBlockData(theblock,&rFILE,&len);
  504.             err = SendStr(ref,"Mac_Spec,Name='%s',vRefNum=%d,parID=%d",
  505.                                                     (long)rFILE.name,rFILE.vRefNum,rFILE.parID);
  506.             break;
  507.         case bMACP:
  508.             len = 256;
  509.             if (p = NewPtr(256)) {
  510.                 ExtractBlockData(theblock,p,&len);
  511.                 err = SendStr(ref,"Mac_Path='%s'",(long)p);
  512.                 DisposPtr(p);
  513.             }
  514.             break;
  515.         case bDOSF:
  516.             len = 256;
  517.             if (p = NewPtr(256)) {
  518.                 ExtractBlockData(theblock,p,&len);
  519.                 err = SendStr(ref,"DOS_File='%s'",(long)p);
  520.                 DisposPtr(p);
  521.             }
  522.             break;
  523.         case bFRMS:
  524.             len = sizeof(long);
  525.             ExtractBlockData(theblock,&lvalue,&len);
  526.             err = SendStr(ref,"Num_Frames=%d",lvalue);
  527.             break;
  528.         case bVIDI:
  529.             len = sizeof(Rec_VIDI);
  530.             ExtractBlockData(theblock,&rVIDI,&len);
  531.             err = SendStr(ref,
  532.                               "Video,Width=%d,Height=%d,Depth=%d",
  533.                               (long)rVIDI.frame.right,
  534.                               (long)rVIDI.frame.bottom,
  535.                               (long)rVIDI.depth);
  536.             break;
  537.         case bAUDI:
  538.             len = sizeof(long);
  539.             ExtractBlockData(theblock,&lvalue,&len);
  540.             err = SendStr(ref,"Audio,Rate=%d",lvalue);
  541.             break;
  542.         case bTIMC:
  543.             if (pblock = NewPtr(256))
  544.             {
  545.                 len = 256;
  546.                 ExtractBlockData(theblock,pblock,&len);
  547.                 err = SendStr(ref,"Timecode String='%s'",(long)pblock);
  548.                 DisposPtr(pblock);
  549.             }
  550.             break;
  551.         case bTIMB:
  552.             len = sizeof(Rec_TIMB);
  553.             ExtractBlockData(theblock,&rTIMB,&len);
  554.             err = SendStr(ref,
  555.                               "Timecode Block,Frame=%d,DropFrame=%d,Format=%d",
  556.                               rTIMB.frames,
  557.                               (long)rTIMB.dropframe,
  558.                               (long)rTIMB.format);
  559.             break;
  560.         case bREEL:
  561.             if (pblock = NewPtr(256))
  562.             {
  563.                 len = 256;
  564.                 ExtractBlockData(theblock,pblock,&len);
  565.                 err = SendStr(ref,"Reel_Name='%s'",(long)pblock);
  566.                 DisposPtr(pblock);
  567.             }
  568.             break;
  569.             
  570.         default:
  571.             err = SendStr(ref,"'*** Unknown: '%t' #%d, %d bytes",
  572.                                                         theblock->type,theblock->theID,theblock->dataSize);
  573.             break;
  574.     }
  575.     
  576.     if (!err)
  577.         if ((unsigned)theblock->size > (sizeof(BlockRec) + theblock->dataSize))
  578.         {
  579.             err = SendChar(ref,',');
  580.             if (!err) err = SendChar(ref,13);
  581.             if (!err) err = SendChar(ref,10);    
  582.             count = (short)CountTypeBlocks(-1,theblock);
  583.             for (i=0; !err && (i<count); i++)
  584.                 err = ParseBlock(FindBlock(-1,-1,i,theblock),ref,indent+1);
  585.             SendIndent(ref,indent);
  586.         }
  587.     if (!err) err = SendChar(ref,']');
  588.     if (!err && indent) err = SendChar(ref,',');
  589.     if (!err) err = SendChar(ref,13);
  590.     if (!err) err = SendChar(ref,10);    
  591.     return(err);
  592. }
  593.